define(function(require, exports, module) {
	
	function FlowUp($obj) {
		$obj.animate({
			top: 1000
		}, 2000, function(){
			$obj.remove();
		});
	}
	
	return {
		ActionArray : [ "drop", "Snowflake", "Pop" ],

		Actions : {
			"drop" : {
				name : '晃动窗口',
				action : 'drop'
			},
			"Snowflake" : {
				name : '恐怖血花',
				action : 'Snowflake'
			},
			"Pop" : {
				name : '无限弹窗',
				action : 'Pop'
			}
		},

		sendActions : function(a, toUser, showActionPanal, ischeck) {
			var action = 'cmd●action□{"fromuser":"' + top.user.userId + '",'
					+ '"touser":"' + toUser + '",' + '"action":"'
					+ this.Actions[a].action + '"}';
			top.yinsin.sendData(action);
			var time = CommonUtil.formatTime('yyyy-MM-dd HH:mm:ss', new Date());
			this.showInfos(
				toUser,
				$('#touser-name').text(),
				a,	time,	toUser == 'all_user' ? 3 : 4
			);
			if(ischeck){
				this.showAction({
					fromName: '',
					action: this.Actions[a].action,
					time: '',
					flag: '2'
				}, true);
			}
			showActionPanal && showActionPanal();
			
			this.sendActionTimeout();
		},
		
		timeout: 0,
		
		sendActionTimeout: function(){
			$cover = $('<div class="action-cover" id="timeout-cover">60</div>');
			$('#tools-div').append($cover);
			var $this = this;
			$this.timeout = 60;
			var inter = setInterval(function(){
				$this.timeout--;
				$('#timeout-cover').text($this.timeout);
				if($this.timeout < 1){
					$cover.remove();
					clearInterval(inter);
					$this.timeout = 0;
				}
			}, 1000);
		},

		showAction : function(data, islocal) {
			var fromUser = data.fromName;
			var action = data.action;
			var time = data.time;
			var flag = data.flag;
			islocal || this.showInfos(data.fromId, fromUser, action, time, flag);
			if (flag != '3' && flag != '4') {
				switch (action) {
				case 'drop':
					this.drop();
					break;
				case 'Snowflake':
					this.Snowflake();
					break;
				case 'Pop':
					this.Pop();
					break;
				}
			}
		},

		showInfos : function(fromId, fromUser, action, time, flag) {
			var us = '<span uid="'+fromId+'" class="tou atuser">['+fromUser+']</span>';
			var texts = us + '&nbsp;向大家发送了';
			if (flag == '2') {
				texts = us + '&nbsp;向你发送了';
			} else if (flag == '3') {
				texts = '&nbsp;你向<font color="blue">大家</font>发送了';
			} else if (flag == '4') {
				texts = '&nbsp;你向' + us + '发送了';
			}
			var $msg = $('<div class="message errorInfo">' + time + '&nbsp;'
			+ texts + '[<font color="red">'
			+ this.Actions[action].name + '</font>]动作！' + '</div>');
			$("#info").append($msg);
			
			$msg && $msg.find('.tou.atuser').on('click', function(e){
				var uid = $(this).attr('uid');
				var $touser = $('#' + uid);
				if($touser.length > 0){
					var $parent = $touser.parent();
					if($parent.is(":hidden")){
						$parent.show();
						$parent.prev().removeClass('close');
					}
					top.chooseUser($touser);
					$('#userListDiv').animate({scrollTop: $touser.offset().top}, 1000);
				}
			}).on('mouseover', function(e){
				top.showUserInfoPanal(e, $(this));
			}).on('mouseout', function(e){
				top.hiddenUserInfoPanal($(this));
			});
			
			top.scrollInfo();
		},

		showAlert : function(data) {
			var flag = data.flag;
			if (flag == 'failed') {
				alert('你没有权限使用此动作！');
			}
		},

		drop : function() {
			var $snow = $('#info').clone().css('position', 'absolute');
			$('#info').css('visibility', 'hidden');
			$(document.body).append($snow);
			var count = 0, left = 0, top = 0;
			var run1 = function(){
				count++;
				if(count < 100){
					left = Math.ceil(Math.random() * ($(document).width() - $snow.width())) + 'px';
					top = Math.ceil(Math.random() * ($(document).height() - $snow.height())) + 'px';
					$snow.animate({
						left: left, top: top
					}, 50, run2);
				} else {
					$snow.remove();
					$('#info').css('visibility', 'visible');
				}
			};
			var run2 = function(){
				count++;
				left = Math.ceil(Math.random() * ($(document).width() - $snow.width())) + 'px';
				top = Math.ceil(Math.random() * ($(document).height() - $snow.height())) + 'px';
				if(count < 100){
					$snow.animate({
						left: left, top: top
					}, 50, run1);
				} else {
					$snow.remove();
					$('#info').css('visibility', 'visible');
				}
			};
			run1();
		},

		Snowflake : function() {
			var time = 0, Interval = 0, left = 0;
			function start() {
				if (time < 200) {
					time++;
					for(var i = 0; i < 5; i++){
						left = Math.ceil(Math.random() * $(document).width()) + 'px';
						var $snow = $('<div class="snowflake">※</div>').css('left', left);
						$(document.body).append($snow);
						new FlowUp($snow);
					}
				} else {
					window.clearInterval(Interval);
				}
			}
			Interval = window.setInterval(start, 1);
		},

		langu : [ "这是无限弹出！", "你是关不掉的！", "怎么样是不是很想揍他！", "不过看你好像也没种！",
				"哈哈，烦躁之时我给你讲个故事把！", "从前有座山", "山上有座庙", "庙里有个老和尚和一个小和尚",
				"老和尚对小和尚说：", "我给你讲个故事把！", "从前有座山", "山上有座庙", "庙里有个老和尚和一个小和尚",
				"老和尚对小和尚说：", "我给你讲个故事把！", "从前有座山", "山上有座庙", "庙里有个老和尚和一个小和尚",
				"老和尚对小和尚说：", "我给你讲个故事把！", "从前有座山", "山上有座庙", "庙里有个老和尚和一个小和尚",
				"老和尚对小和尚说：", "我给你讲个故事把！", "从前有座山", "山上有座庙", "庙里有个老和尚和一个小和尚",
				"老和尚对小和尚说：", "我给你讲个故事把！", "从前有座山", "山上有座庙", "庙里有个老和尚和一个小和尚",
				"老和尚对小和尚说：", "我给你讲个故事把！", "是不是听烦拉！", "唉，我都讲烦了！", "算了饶过你把！",
				"拜拜！", "下次再见！" 
		],
				
		Pop : function() {
			for ( var i = 0; i < this.langu.length; i++) {
				var laug = this.langu[i];
				alert(laug);
			}
		}

	};

});